${light}

${material}

${fog}

${function}

${shadow}

uniform ece_LightSource light[MaxLightCount];
uniform ece_Material material1;
uniform ece_Material material2;
uniform ece_Fog fog;
uniform ece_ShadowMapping shadow;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform vec3 viewPosition;
varying vec2 vTexCoord;
varying float vTexAlpha;
varying vec3 vNormal;
varying vec4 vShadowCoord; 
varying vec3 vPosition;
varying float vDistance;
void main() {
	vec4 baseColor1 = texture2D(texture1, vTexCoord);
	vec4 baseColor2 = texture2D(texture2, vTexCoord);
	vec4 baseColor = mix(baseColor1, baseColor2, vTexAlpha);
	
	ece_Material material;
	material.enable = true;
	material.emission = mix(material1.emission, material2.emission, vTexAlpha);
	material.ambient = mix(material1.ambient, material2.ambient, vTexAlpha);
	material.diffuse = mix(material1.diffuse, material2.diffuse, vTexAlpha);
	material.specular = mix(material1.specular, material2.specular, vTexAlpha);
	material.shininess = mix(material1.shininess, material2.shininess, vTexAlpha);
	
	vec3 normal = normalize(vNormal);
	vec3 viewDir = normalize(viewPosition - vPosition);
	float shininess = material.shininess;
	
	vec3 ambient = vec3(0);
	vec3 diffuse = vec3(0);
	vec3 specular = vec3(0);
	
	LightPixel(light, vPosition, normal, viewDir, shininess, ambient, diffuse, specular);
	
    vec3 color = vec3(0.0);
    if(shadow.enable) {
    	vec3 lightDir = normalize(light[shadow.lightIndex].position.xyz - vPosition);
		float shadowResult = calculateShadow(shadow.shadowMapping, vShadowCoord, lightDir, normal);
		MaterialMixWithShadow(material, shadowResult, ambient, diffuse, specular, baseColor.rgb, color); 
    } else {
    	MaterialMix(material, ambient, diffuse, specular, baseColor.rgb, color);
    }
    FogMix(fog, vDistance, color);
	gl_FragColor = vec4(color, baseColor.a);
}